package equals;

import java.util.Objects;

public class Customer {

	public String name;

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Customer customer = (Customer) o;
		return age == customer.age &&
				Objects.equals(name, customer.name);
	}



	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Customer() {
		super();
	}

	public Customer(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return "Customer{" +
				"name='" + name + '\'' +
				", age=" + age +
				'}';
	}
}

//	@Override
// 手写实现equals()重写
//	public boolean equals(Object obj) {
//		if (this == obj) {
//			return true;
//		}
//
//		if (obj instanceof Customer) {
//			Customer cust = (Customer)obj; //同级或者子类强制为高级的类 即子转父
////			if(this.age == cust.age && this.name.equals(cust.name)) { //这里的equals调用的是String重写的equals，
////						return true;											  // 因为比较的是String，所以用String的equals
////																	  //八大类型没有string，刚讲字符串类型String中被重写了，比较内容，name是String类型，
////																	  // 所以比较内容
////			}else {
////				return false;
////			}
//			return this.age == cust.age && this.name.equals(cust.name);
//		}
//
//		return false;
//	}
//}
